- content_for(:title)
  = t(".title")
= render 'shared/header_big'
.w-row.admin.use-sort
  h1= @title = t('.title')
  = simple_form_for admin_users_path, method: :get, class: 'form-horizontal' do |form|
    = form.hidden_field :order_by, name: :order_by, value: params[:order_by]
    fieldset
      .w-row
        .w-col-2.w-col
          = form.input :by_id, as: :integer, label: t('.by_id'), input_html: {value: params[:by_id], name: :by_id}
        .w-col-2.w-col
          = form.input :by_name, as: :string, label: t('.by_name'), input_html: {value: params[:by_name], name: :by_name}
        .w-col-2.w-col
          = form.input :by_email, as: :string, label: t('.by_email'), input_html: {value: params[:by_email], name: :by_email}
        .w-col-2.w-col
          = form.input :by_payer_email, as: :string, label: t('.by_payer_email'), input_html: {value: params[:by_payer_email], name: :by_payer_email}
        .w-col-2.w-col
          = form.input :by_key, as: :string, label: t('.key'), input_html: {value: params[:by_key], name: :by_key}
      .w-row
        fieldset
        .w-col-2.w-col
          = check_box_tag :has_credits, true, params[:has_credits].present?
          = form.label :has_credits, t('.credits')
        .w-col-2.w-col
          = form.button :submit, t('admin.filter.submit'), class: 'button medium negative'

  = paginate @users
  - if @users.empty?
    = t('.no_users')
  - else
    table.table.fontsize-smallest
      thead.card.card-secondary
        tr
          th.w-col-1.w-col= t('.id')
          th.w-col-3.w-col= t('.user')
          th.w-col-3.w-col= t('.email')
          th.w-col-2.w-col
            a data-sort="coalesce(user_totals.sum,0)" href='#'= t('.total_contributed')
            span.sort-order
          th.w-col-2.w-col
            a data-sort="coalesce(user_totals.credits,0)" href='#'= t('.credits')
            span.sort-order
      tbody
        - for user in @users do
          tr id=user.id class=cycle("card", "card card-secondary")
            td.w-col-1.w-col= link_to user.id, edit_user_path(user), target: '_blank'
            td.w-col-3.w-col= link_to user.name, admin_contributions_path(by_user_id: user.id), target: '_blank'
            td.w-col-3.w-col= user.email
            td.w-col-2.w-col= user.user_total ? user.user_total.sum : 0
            td.w-col-2.w-col= user.credits
  = paginate @users
  .clearfix
= render 'shared/footer_big'
